/*
 * @Author: your name 分类模块
 * @Date: 2022-01-21 16:18:57
 * @LastEditTime: 2022-01-25 17:24:33
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \eribbit-client-pc\src\store\modules\category.js
 */

import { topCategory } from '@/api/constants'
import { findAllCategory } from '@/api/category'
export default {
  namespaced: true,
  state () {
    return {
      // 分类信息集合，依赖topCategory重新设置，保证初始化就要数据，不要白屏
      list: topCategory.map(item => ({ name: item }))

    }
  },

  // 修改分类函数
  mutations: {
    setList (state, payLoad) {
      state.list = payLoad
    }
  },

  // 获取分类函数
  actions: {
    async  getList ({ commit }) {
      // 获取分类数据
      const data = await findAllCategory()
      commit('setList', data.result)
    }
  }

}
